package trigger.gui;

import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class NumberField extends JTextField {
    /**
	 * 
	 */
	private static final long serialVersionUID = -3994537649972878338L;

	public NumberField()
        {
            this( null );
        }

        @SuppressWarnings("serial")
		public NumberField( String text )
        {
            super(text);
            setDocument(new PlainDocument()
            {
                public void insertString( int offs, String str, AttributeSet a ) throws BadLocationException
                {
                    for( int i = 0; i < str.length(); i++ )
                    if( Character.isDigit( str.charAt( i ) ) == false )
                        return;
                super.insertString( offs, str, a );
            }
        } );
        }
}
